package com.rui1024.util;

import org.junit.Test;
import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


public class Md5Util {

    public static String encoderPwdByMd5(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        BASE64Encoder base64Encoder = new BASE64Encoder();
        return base64Encoder.encode(md5.digest(str.getBytes("utf-8")));
    }

    @Test
    public void test() throws UnsupportedEncodingException, NoSuchAlgorithmException {
        Md5Util md5Util = new Md5Util();
        String pwd = md5Util.encoderPwdByMd5("123");
        System.out.println(pwd);
    }
}
